/**
 * FileName: Base64Encoder
 * Author:   SAGIRI
 * Date:     2019/5/14 0014 9:46
 * Description: base64加解密
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ruimei.util;

import java.io.IOException;
import java.util.Base64;

/**
 * 〈base64加解密〉
 *
 * @author SAGIRI
 * @create 2019/5/14 0014
 * @since 1.0.0
 */
public class Base64Encoder {
    /**
     * 加密
     * @param userinfo
     * @return
     * @throws IOException
     */
    public static String encoder(String userinfo)  {
        Base64.Encoder encoder = null ;
        byte[] bytes =  null;
        try{
            encoder = Base64.getEncoder();
            bytes = userinfo.getBytes("UTF-8");
        }catch (Exception e){
            e.printStackTrace();
        }

        return encoder.encodeToString(bytes);

    }

    /**
     * jiemi
     * @param base64String
     * @return
     * @throws IOException
     */
    public static String decoder(String base64String) throws IOException{
        Base64.Decoder decoder = null;
        byte[] bytes = null;
        try{
            decoder =   Base64.getDecoder();
            bytes = base64String.getBytes("UTF-8");
        }
    catch (Exception e){
        e.printStackTrace();
    }

        return new String(decoder.decode(bytes),"UTF-8");
    }

    public static void main(String[] args) throws IOException{

        System.out.println(Base64Encoder.decoder("dGVhY2hlcl80ZjlkZDM4ZTIwMmQ0MmRlODhlNTMzYWFmMjNiYTBhMA=="));
    }
}